from fastapi import APIRouter, status, Cookie, HTTPException

from typing import Annotated, Optional

from src.region_service.services.region_type import regionType_service
from src.region_service.schemas import (
    Upload_regionType_form
)

regionType_router = APIRouter(prefix="/region/types", tags=["regionType"])


@regionType_router.post(
    "",
    # response_model=Full_regionType_schema,
    status_code=status.HTTP_201_CREATED
)
async def create_type_region(
    payload: Upload_regionType_form,
    id: Annotated[int | None, Cookie()] = None
):
    return await regionType_service().create_regionType(
        payload,
        user_id=id
    )


@regionType_router.get(
    "/{type_id}",
    # response_model=Full_regionType_schema,
    status_code=status.HTTP_200_OK
)
async def get_regionType(
    type_id: Optional[int],
    id: Annotated[int | None, Cookie()] = None
):
    if type_id is None or type_id <= 0:
        raise HTTPException(status_code=400, detail="bad data")
    return await regionType_service().get_regionType(
        type_id,
        user_id=id
    )


@regionType_router.put(
    "/{type_id}",
    # response_model=Full_regionType_schema,
    status_code=status.HTTP_200_OK
)
async def edit_regionType(
    type_id: int,
    payload: Upload_regionType_form,
    id: Annotated[int | None, Cookie()] = None
):
    if type_id is None or type_id <= 0:
        raise HTTPException(status_code=400, detail="bad data")

    return await regionType_service().edit_regionType(
        type_id,
        payload,
        user_id=id
    )


@regionType_router.delete(
    "/{type_id}",
    status_code=status.HTTP_200_OK
)
async def delete_regionType(
    type_id: int,
    id: Annotated[int | None, Cookie()] = None
):
    if type_id is None or type_id <= 0:
        raise HTTPException(status_code=400, detail="bad data")

    return await regionType_service().delete_regionType(
        type_id,
        user_id=id
    )
